<template>
  <view class="main">
    <view class="title">个人资料</view>
    <u-cell-group :border="false">
      <u-cell :title="userInfo?.nickName">
        <template #value>
          <image class="img" :src="userInfo?.avatar" />
        </template>
      </u-cell>
      <u-cell :border="false" title="绑定手机号">
        <template #value>
          <view style="color: #cbcccc">{{ userInfo?.mobile || "去授权" }} </view>
        </template>
      </u-cell>
    </u-cell-group>
    <view class="title">隐私设置</view>
    <u-cell-group :border="false">
      <u-cell title="允许添加好友">
        <template #value>
          <u-switch v-if="userInfo?.allowAdd" @change="switchChange" v-model="userInfo.allowAdd" activeColor="#1676fc" activeValue="1" inactiveValue="0"></u-switch>
        </template>
      </u-cell>
      <u-cell title="推送设置" isLink :value="getTSSZName()" @click="goPage('/pages/myPage/setting/editPage?pageType=1')"> </u-cell>
      <u-cell :border="false" title="隐私声明" isLink @click="goPage('/pages/myPage/setting/privacyStatementList')"> </u-cell>
    </u-cell-group>
    <view class="title">通用设置</view>
    <u-cell-group :border="false">
      <u-cell title="修改支付密码" isLink @click="goPage('/pages/myPage/setting/editPage?pageType=2')"> </u-cell>
      <u-cell title="绑定支付宝" isLink @click="goPage('/pages/myPage/setting/editPage?pageType=3')"> </u-cell>
    </u-cell-group>
    <u-cell-group :border="false">
      <u-cell title="退出登录" isLink @click="layout"> </u-cell>
    </u-cell-group>
  </view>
</template>

<script setup lang="ts">
import { ref } from "vue";
import { goPage } from "../../../utils/commonFn";
// @ts-ignore
import { onShow } from "@dcloudio/uni-app";
import { changeAllowAdd, getUserInfo, logoutApi } from "@/api/my";
const userInfo = ref<myTypes.userInfo>();
onShow(async () => {
  const res = await getUserInfo();
  userInfo.value = res.data;
  uni.setStorageSync("userInfo", res.data);
});
const getTSSZName = () => {
  if (userInfo.value?.sendStartTime) {
    return userInfo.value?.sendStartTime + "-" + userInfo.value?.sendEndTime;
  } else {
    return "请设置";
  }
};
const switchChange = async (e: string) => {
  await changeAllowAdd({ status: e });
};
const layout = async () => {
  uni.clearStorageSync();
  await logoutApi();
  uni.switchTab({
    url: "/pages/home/home",
  });
};
</script>

<style lang="less" scoped>
@import "./css/cell-group.scss";

.title {
  font-size: 26rpx;
  color: #969696;
  line-height: 36rpx;
  padding-left: 32rpx;
  margin-top: 20rpx;
}
</style>
